package com.wyp.java8;

import java.util.Arrays;
import java.util.List;


public class StreamDemo3 {
    public static void main(String[] args) {
        User u1=new User(11,"f",23, User.Status.FREE);
        User u2=new User(12,"m",24, User.Status.BUSY);
        User u3=new User(13,"c",22, User.Status.VOCATION);
        User u4=new User(14,"d",28, User.Status.FREE);
        User u5=new User(16,"e",27, User.Status.VOCATION);

        List<User> list = Arrays.asList(u1,u2,u3,u4,u5);

//        System.out.println(list.stream().noneMatch((e) -> {
//            return e.getStatus().equals(User.Status.BUSY);
//        }));
        //System.out.println(list.stream().sorted((e1, e2) -> Integer.compare(e1.getAge(), e2.getAge())).findFirst());

        // 串行  查找
//        System.out.println(list.stream().filter(e -> {
//            return e.getStatus().equals(User.Status.FREE);
//        }).findAny());
        // 并行
//        System.out.println(list.parallelStream().filter(e -> {
//            return e.getStatus().equals(User.Status.FREE);
//        }).findAny());

        System.out.println(list.stream().filter(e -> {
            return e.getStatus().equals(User.Status.FREE);
        }).count());

        System.out.println(list.stream().filter(e -> {
            return e.getStatus().equals(User.Status.FREE);
        }).max((e1, e2) -> Integer.compare(e1.getAge(), e2.getAge())));
    }
}